<template>
<div class="edit-record">
  <div class="edit-record-content">
     <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="article-item" v-for="(item,index) in myWriteList" :key="index" @click="enterDetail(item)">
        <div class="content scale-1px-bottom">
          <div class="left-cnt">
            <h3 class="title">{{item.title}}</h3>
            <div class="attr">
              <p class="source">
                <span class="time">{{item.createTimeStamp | formatData}}</span>
              </p>
            </div>
          </div>
          <div class="img">
            <img :src="item.image" alt="">
          </div>
        </div>
      </div>
     </van-list>
  </div>
</div>
</template>
<script>
import timeUtils from '@/utils/timeUtils'
import userService from 'SERVICE/userService'
export default {
  data() {
    return {
      loading: false,
      finished: false,
      current: 1,
      myWriteList:[]
    }
  },
  filters: {
    formatData(time) {
      return timeUtils.fmtDateNoSecond(time)
    }
  },
  methods: {
    async onLoad() {
      //获取选中的位置
      const res = await userService.queryWriteArticleList(3, this.current, '')
      if (res.records.length > 0) {
        this.myWriteList = this.myWriteList.concat(res.records)
        if (res.pages === 0 || this.current === res.pages) {
          this.finished = true
        }
        this.current++
        this.loading = false
      } else {
        if (this.current == 1) {
        }
        this.loading = false
        this.finished = true
      }
    },
    enterDetail(val) {
      val.selectType = 3;
      val.from = 'editRecords'
      console.log("编辑记录页",val);
      this.$router.push({ path: '/user/articles/easyLookChildList', query: val })
    },
    // 浏览器回退监听
    goBack () {
      this.$router.replace({path:'/discover/newlyAdded'});
    }
  },
  // mounted() {
  //   if (window.history && window.history.pushState) {
  //     history.pushState(null, null, document.URL);
  //     window.addEventListener('popstate', this.goBack, false);
  //   }
  // },
  // destroyed() {
  //   window.removeEventListener('popstate', this.goBack,false)    
  // },
}
</script>
<style lang="less" scoped>
.edit-record{
  background: #F7F9FA;
  padding-bottom: 16px;
  .edit-record-content{
    padding: 0 16px;
    background: #fff;
  }
}
.article-item {
  height: 111px;
  overflow: hidden;
  &.noborder {
    border: none;
  }
  .content {
    display: flex;
    padding: 14px 0;
    align-items: center;
    overflow: hidden;
    .left-cnt {
      flex: 1;
      height: 83px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      margin-right: 14px;
      .title {
        font-size: 16px;
        line-height: 24px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2; //（行数）
        -webkit-box-orient: vertical;
        word-break: break-all;
      }
      .attr {
        color: #9CA5B5;
        font-size: 12px;
        line-height: 16px;
        display: flex;
        align-items: center;
        .source {
          flex: 1;
          .name {
            display: inline-block;
            margin-right: 8px;
            max-width: 60px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            vertical-align: middle;
          }
          .time {
            display: inline-block;
            vertical-align: middle;
          }
        }
        .read {
          line-height: 16px;
          min-width: 60px;
          text-align: right;
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
    .img {
      width: 114px;
      height: 78px;
      border-radius: 6px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 6px;
        object-fit: cover;
      }
    }
  }
}
</style>
